//
//  ASPersonViewController.m
//  AttendenceSys
//
//  Created by ld on 16/1/14.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASPersonViewController.h"
#import "ASPersonCell.h"
#import "ASLoginUserInfo.h"
#import "ASBasicInfoVC.h"
#import "ASMyCollectionVC.h"
#import "ASMyMessageVC.h"
#import "ASSettingViewController.h"


@interface ASPersonViewController ()

@property(nonatomic, strong) ASLoginUserInfo* userInfo;

@end

@implementation ASPersonViewController

- (void)initView
{
    _infoTypeArr = @[@"基本信息", @"我的收藏", @"我的消息", @"设置"];
    _leftBgImage = @[@"ic_information", @"ic_collection", @"ic_news", @"ic_set"];
    
    UIImageView* bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.image = [UIImage imageNamed:@"bg_personal"];
    bgView.userInteractionEnabled = YES;
    [self.view addSubview:bgView];
    
    // userName
    _userName = [[UILabel alloc] initWithFrame:CGRectMake(0, 14, self.view.frame.size.width, 20)];
    [_userName setBackgroundColor:[UIColor clearColor]];
    [_userName setText:_userInfo.userName];
    [_userName setTextColor:[UIColor blackColor]];
    [_userName setTextAlignment:NSTextAlignmentCenter];
    _userName.font = [UIFont fontWithName:@"Arial" size:16.0];
    [bgView addSubview:_userName];
    
    // headImage
    _headImage = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 90) / 2,
                                                               _userName.frame.origin.y + _userName.frame.size.height + 8,
                                                               90,
                                                               90)];
    _headImage.backgroundColor = [UIColor clearColor];
    _headImage.image = [UIImage imageNamed:@"person_portrait_3"];
    [bgView addSubview:_headImage];
    
    // collegeName
    _collegeName = [[UILabel alloc] initWithFrame:CGRectMake(0,
                                                             _headImage.frame.origin.y + _headImage.frame.size.height + 8,
                                                             self.view.frame.size.width,
                                                             20)];
    [_collegeName setBackgroundColor:[UIColor clearColor]];
    [_collegeName setText:_userInfo.collegeName];
    [_collegeName setTextColor:[UIColor blackColor]];
    [_collegeName setTextAlignment:NSTextAlignmentCenter];
    _collegeName.font = [UIFont fontWithName:@"Arial" size:15.0];
    [bgView addSubview:_collegeName];
    
    // className
    _className = [[UILabel alloc] initWithFrame:CGRectMake(0,
                                                           _collegeName.frame.origin.y + _collegeName.frame.size.height + 4,
                                                           self.view.frame.size.width,
                                                           20)];
    [_className setBackgroundColor:[UIColor clearColor]];
    [_className setText:_userInfo.className];
    [_className setTextColor:[UIColor blackColor]];
    [_className setTextAlignment:NSTextAlignmentCenter];
    _className.font = [UIFont fontWithName:@"Arial" size:14.0];
    [bgView addSubview:_className];
    
    // infoTableView
    _infoTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _infoTableView.frame = CGRectMake(0,
                                      _className.frame.origin.y + _className.frame.size.height + 14,
                                      self.view.frame.size.width,
                                      200);
    _infoTableView.delegate = self;
    _infoTableView.dataSource = self;
    _infoTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _infoTableView.backgroundColor = [UIColor whiteColor];
    [_infoTableView registerClass:[ASPersonCell class] forCellReuseIdentifier:NSStringFromClass([ASPersonCell class])];
    [bgView addSubview:_infoTableView];
    
    // 退出登录
    _logoutBtn = [[UIButton alloc] initWithFrame:CGRectMake(55,
                                                            _infoTableView.frame.origin.y + _infoTableView.frame.size.height + 28,
                                                            self.view.frame.size.width - 2 * 55,
                                                            50)];
    [_logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [_logoutBtn addTarget:self action:@selector(logout) forControlEvents:UIControlEventTouchUpInside];
    [_logoutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _logoutBtn.backgroundColor = RGB(253, 119, 62);
    [bgView addSubview:_logoutBtn];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _userInfo = [ASAppDelegate sharedAppDelegate].userInfo;
    [self initView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)logout
{
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (0 == [indexPath row])
    {
        ASBasicInfoVC* basicInfoVC = [[ASBasicInfoVC alloc] init];
        [self.navigationController pushViewController:basicInfoVC animated:YES];
    }
    else if (1 == [indexPath row])
    {
        ASMyCollectionVC* collecVC = [[ASMyCollectionVC alloc] init];
        [self.navigationController pushViewController:collecVC animated:YES];
    }
    else if (2 == [indexPath row])
    {
        ASMyMessageVC* msgVC = [[ASMyMessageVC alloc] init];
        [self.navigationController pushViewController:msgVC animated:YES];
    }
    else if (3 == [indexPath row])
    {
        ASSettingViewController* setVC = [[ASSettingViewController alloc] init];
        [self.navigationController pushViewController:setVC animated:YES];
    }
    else
    {
        return;
    }
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_infoTypeArr count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ASPersonCell class])];
    
    [(ASPersonCell*)cell updateCellStatus:[_leftBgImage objectAtIndex:[indexPath row]]
                                 cellName:[_infoTypeArr objectAtIndex:[indexPath row]]
                                 rowIndex:[indexPath row]];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}



@end
